package com.hidt.shop.controller;

import com.hidt.shop.domain.Seckil;
import com.hidt.shop.service.SeckilService;
import com.hidt.shop.util.RestDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Fhy
 * @Title SeckilController
 * @Package com.hdit.shop.controller
 * @Description 商品秒杀表接口
 * @date 2021/1/21 16:08
 */
@RestController
public class SeckilController {
    @Autowired
    private SeckilService seckilService;

    @RequestMapping("/addSeckil")
    public RestDate addSeckil(@RequestBody Seckil seckil) {
        RestDate restDate = seckilService.addSeckil(seckil);

        return restDate;
    }

    @RequestMapping("/deleteSeckil")
    public Map deleteSeckil(@RequestBody Map<String,Integer> map) {
        int seckilId = map.get("seckil_id");
        int goodsId = map.get("goods_id");
        String message = seckilService.deleteSeckil(seckilId, goodsId);

        Map<String,String> callMap = new HashMap<>();
        callMap.put("message", message);
        return callMap;
    }

    @RequestMapping("/updateSeckil")
    public Map updateSeckil(@RequestBody Seckil seckil) {
        String message = seckilService.updateSeckil(seckil);

        Map<String,String> callMap = new HashMap<>();
        callMap.put("message", message);
        return callMap;
    }

    @RequestMapping("/findAllSeckil")
    public List<Seckil> findAllSeckil(@RequestBody Map<String,Integer> map) {
        List<Seckil> seckilList = seckilService.findAllSeckil(map.get("seckildate_id"));
        return seckilList;
    }
}
